::/**
:: * @file        build.bat
:: * @brief       XXXX
:: * @note        XXXX
:: * @author      靳普诏(puzhao.jin@hopechart.com)
:: * @date        2024/07/22
:: * @version     1.0
::
:: * @par         修改日志
:: * <table>
:: * <tr><th>Date         <th>Version     <th>Author      <th> Description
:: * <tr><td>2024/07/22   <td>1.0         <td>靳普诏       <td> 创建初始版本
:: * @copyright   xxxx
:: */

@echo off
:: ============================= 获取环境参数 ================================

set ARGV_LEN=%#
::echo "There are %ARGV_LEN% arguments passed to the build.bat"

set i=1
:show_argument
if %i% gtr %ARGV_LEN% goto end_show_argument

set arg=!%i%!
::echo "Argument %i%: %arg%"

set /a i+=1
goto show_argument

:end_show_argument
::echo "All arguments printed"

:: 脚本所在路径
set SCRIPT_DIR=%~dp0
echo "SCRIPT_DIR=%SCRIPT_DIR%"
:: 当前工作路径
set CURRENT_DIR=%cd%
echo "CURRENT_DIR=%CURRENT_DIR%"    


echo "============================= 配置编译环境 ================================"

set PYTHON=D:\ProgramData\anaconda3\python.exe
set VIRTUAL_ENV=%SCRIPT_DIR%\py_venv
set SRC_DIR=%SCRIPT_DIR%\..\src


echo PYTHON=%PYTHON%
echo VIRTUAL_ENV=%VIRTUAL_ENV%
echo SRC_DIR=%SRC_DIR%


echo "cd %SCRIPT_DIR%"
cd %SCRIPT_DIR%


echo "============= BIGEN: build.bat ============="


if not exist "%VIRTUAL_ENV%" (
    echo "Virtual env not exist, create it"
	
	"%PYTHON%" -m pip install pipreqs
	"%PYTHON%" -m pipreqs "%SRC_DIR%" "%SCRIPT_DIR%\requirements.txt"
	cat "%SCRIPT_DIR%\requirements.txt"
	
	echo "%PYTHON% -m venv %VIRTUAL_ENV%"
    "%PYTHON%" -m venv "%VIRTUAL_ENV%"
	
	call "%VIRTUAL_ENV%\Scripts\activate"
	echo "Activate virtual env --> 进入虚拟环境"

    python -m pip install --upgrade pip 
	
	pip install pyinstaller
	
	echo "安装依赖库"
	pip install -r "%SCRIPT_DIR%\requirements.txt" 
	
) else (

call "%VIRTUAL_ENV%\Scripts\activate"
echo "Activate virtual env"
)



echo "============= pyinstaller begin============="

set MAIN_PY="%SRC_DIR%\main.py"

::pyinstaller --add-data "%SRC_DIR%\ref\templates\*.j2;ref\templates" ^
::            --add-data "%SRC_DIR%\ref\*.py;ref" ^
::            -F %MAIN_PY%
			
pyinstaller --add-data "%SRC_DIR%\ref\*.*;ref" ^
            -F %MAIN_PY%			
			
echo "============= pyinstaller end============="





cd %CURRENT_DIR%
echo "cd %CURRENT_DIR%"

echo "============= END: build.bat ============="
echo "build.bat return errorlevel:%errorlevel%"

echo "Deactivate virtual env"
call deactivate
pause


:: Generated on "2024-07-22 13:15:46" by the tool "gen_hq_file.py >> V20231119" 


